package com.zq.it.comparator;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

import com.zq.it.pojo.Post;

public class PostComparator implements Comparator<Post> {
    @Override
    public int compare(Post o1, Post o2) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date d1 = format.parse(o1.getCreateTime());
            Date d2 = format.parse(o2.getCreateTime());
            return (int) (d2.getTime() - d1.getTime());
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
}
